package com.uex.dev.manage.common.aop;

import com.uex.dev.manage.common.base.ModelResult;
import com.uex.dev.manage.common.base.ResultCodeConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author wangc
 * @create 2023/10/27
 * @description
 */
@RestControllerAdvice
@Slf4j
public class ExceptionAdvice {
    @ExceptionHandler(IllegalArgumentException.class)
    public ModelResult<?> handleIllegalArgumentException(Exception e) {
        log.warn("fail to handle request: {}", e.getMessage());
        return new ModelResult<>(ResultCodeConstants.PARAM_ERROR.getCode(), e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public ModelResult handleException(Exception e) {
        log.error("fail to handle request", e);
        return ModelResult.SYSTEM_ERROR_RESULT;
    }

}
